<?php

class aoiFrontBookingProcessAction extends sfAction {
	public function execute($request){
    $this->flight_type         = $request->getParameter('flight_type','go-back');
    $this->origin_airport      = $request->getParameter('origin_airport','');
    $this->destination_airport = $request->getParameter('destination_airport','');
    $this->date_go             = $request->getParameter('date_go');
    $this->date_back           = $request->getParameter('date_back');
    $this->passengers          = $request->getParameter('passengers', array('1'));

    $this->go_flights    = $this->getFlights($this->date_go, $this->origin_airport, $this->destination_airport);
    
    if($this->flight_type == 'go-back')
    {
      $this->back_flights  = $this->getFlights($this->date_back, $this->destination_airport, $this->origin_airport);
    }

    $this->places_wanted = count($this->passengers); // todo : replace with place_count in AoiPassengerCategory
	}

  public function getFlights($date, $origin_airport, $destination_airport)
  {
    $flights = array();
    $date_arr = explode('-', $date);

    if(count($date_arr) == 3)
    {
      $date = $date_arr[0].'-'.$date_arr[1].'-'.$date_arr[2];
      $flights = Doctrine_Core::getTable('AoiFlightSchedule')->getFlightsAroundDate($origin_airport, $destination_airport, $date);
    }
    return $flights;
  }
}